package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.utils.BeanHelper;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import com.leyou.user.dto.SpecParamDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author 虎哥
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    @Override
    public List<SpecParam> queryParams(Long categoryId, Long groupId, Boolean searching) {
        QueryWrapper<SpecParam> wrapper = new QueryWrapper<>();
        wrapper.eq(!StringUtils.isEmpty(categoryId),"category_id",categoryId)
                .eq(!StringUtils.isEmpty(groupId),"group_id",groupId)
                .eq(!StringUtils.isEmpty(searching),"searching",searching);
        return this.list(wrapper);
    }

    @Override
    public List<SpecParamDTO> querySpecParams(Long categoryId, Long groupId, Boolean searching) {
        QueryWrapper<SpecParam> wrapper = new QueryWrapper<>();
        wrapper.eq(!StringUtils.isEmpty(categoryId),"category_id",categoryId)
                .eq(!StringUtils.isEmpty(groupId),"group_id",groupId)
                .eq(!StringUtils.isEmpty(searching),"searching",searching);
        return SpecParamDTO.convertEntityList(this.list(wrapper));
    }

}